// ml:run = $bin < input
// ml:opt = 0
// ml:ccf += -g
#include <algorithm>
#include <fstream>

int const maxn = 100007;
int const maxv = 1000007;

struct data { int x, y; };
data da[maxn];
bool vis[maxn];
int ans[maxn];
int px[maxv], py[maxv];
int n, tn, tot;
int x = 1000000, y = 1000000;

int get_minx(int ty, int tx)
{
    int min = tx;
    for (int i = ty + 1; i <= y; i++) {
        if (py[i] == 0 || vis[py[i]]) continue;
        vis[py[i]] = true;
        min = std::min(min, da[py[i]].x);
        ans[py[i]] = tot - 1;
        tn--;
    }
    y = ty;
    return min;
}

int main()
{
    std::ifstream fin{"codecoder.in"};
    std::ofstream fout{"codecoder.out"};
    fin >> n;
    tot = n;
    for (int i = 1; i <= n; i++) {
        fin >> da[i].x >> da[i].y;
        px[da[i].x] = i;
        py[da[i].y] = i;
    }

    for (; x > 0; x--) {
        if (px[x] == 0) continue;
        tn = tot - 1;
        ans[px[x]] = tot - 1;
        vis[px[x]] = true;
        for (int tx = get_minx(da[px[x]].y, x); tx < x && x; ) {
            int miny = y;
            for (int i = tx + 1; i < x; i++) {
                if (px[i] == 0 || vis[px[i]]) continue;
                ans[px[i]] = tot - 1;
                vis[px[i]] = true;
                tn--;
                miny = std::min(miny, da[px[i]].y);
            }
            x = tx;
            tx = get_minx(miny, x);
        }
        tot = tn;
    }

    for (int i = 1; i <= n; i++)
        fout << ans[i] << "\n";
}

